﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SchoolLibrary.Entity;
using SchoolLibrary.DataBase.DAO;

namespace SchoolLibrary.Desktop.Report.Dialog
{
    public partial class ClassSelectDialog : Form
    {
        private Class selectedClass;

        public ClassSelectDialog()
        {
            InitializeComponent();
            initData();
        }

        private void initData()
        {
            List<Class> classes = ClassDAO.getInstance().findAll();
            foreach (Class currentClass in classes)
            {
                this.classSelectComboBox.Items.Add(currentClass);
            }
            if (this.classSelectComboBox.Items.Count > 0)
            {
                this.classSelectComboBox.SelectedIndex = 0;
            }
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            selectedClass = (Class) this.classSelectComboBox.SelectedItem;
            this.Close();
        }

        public Class SelectedClass
        {
            get { return selectedClass; }
        }
    }
}
